



// TypeScript file
module Fighter {

    /**
     * 购买敌机———郭启航
     * 购买敌机方法可进行封装进行简化
     * 预留了九种敌机类型
     * 
     */
    export class BuyEnemyUI extends eui.Component {

        constructor() {
            super();
            this.skinName = "resource/assets/PlaneE/BuyEnemyUI.exml";
            this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
        }
        /**购买敌机页面返回*/
        private BuyEnemy_back: eui.Image;
        /**敌机1*/
        public Enemy1: eui.Image
        /**敌机2*/
        public Enemy2: eui.Image
        /**敌机3*/
        public Enemy3: eui.Image
        /**敌机4*/
        public Enemy4: eui.Image
        /**敌机5*/
        public Enemy5: eui.Image
        /**敌机6*/
        public Enemy6: eui.Image
        /**敌机7*/
        public Enemy7: eui.Image
        /**敌机8*/
        public Enemy8: eui.Image
        /**敌机9*/
        public Enemy9: eui.Image
        /**敌机1的购买数量*/
        public EMY1: eui.Group;
        public E1: number = 0;
        public E1_Num: eui.Label;
        public Enemy1_Price: eui.BitmapLabel;
        public E1Bool: boolean;
        /**敌机2的购买数量*/
        public EMY2: eui.Group;
        public E2: number = 0;
        public E2_Num: eui.Label;
        public Enemy2_Price: eui.BitmapLabel;
        public E2Bool: boolean;
        /**敌机3的购买数量*/
        public EMY3: eui.Group;
        public E3: number = 0;
        public E3_Num: eui.Label;
        public Enemy3_Price: eui.BitmapLabel;
        public E3Bool: boolean;

        /**返回按钮 */
        public Is_back: boolean;
        /**E1CD */
        public E1cd: CdCircle.Circle;
        /**E2CD */
        public E2cd: CdCircle.Circle;
        /**E3CD */
        public E3cd: CdCircle.Circle;
        /**E4CD */
        public E4cd: CdCircle.Circle;
        /**金币显示*/
        private Buyenemy_MoneyShow: eui.BitmapLabel;
        private SubtitleJumped: Fighter.SubtitleJumped = new Fighter.SubtitleJumped();
        public onAddToStage() {
            this.E1=0;
            this.E2=0;
            this.E3=0;
            this.BuyEnemy_back.addEventListener(egret.TouchEvent.TOUCH_TAP, this.Close, this);
            this.addEventListener(egret.Event.ENTER_FRAME, this.Show, this);
            this.EMY1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.Enemy1_money, this);
            this.EMY2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.Enemy2_money, this);
            this.EMY3.addEventListener(egret.TouchEvent.TOUCH_TAP, this.Enemy3_money, this);           
            this.Enemy1_Price.text = GameUtil.PlayerMessage.instance.planeConfig[1].price;
            this.Enemy2_Price.text = GameUtil.PlayerMessage.instance.planeConfig[2].price;
            this.Enemy3_Price.text = GameUtil.PlayerMessage.instance.planeConfig[3].price;         
        }
        /**绘制遮罩*/
        public
        private Close() {
            this.Is_back = true;
        }
        /**每帧更新提示信息*/
        public Show() {
            this.Buyenemy_MoneyShow.text = GameUtil.PlayerMessage.instance.money.toString();
            this.E1_Num.text = "X" + this.E1; this.E2_Num.text = "X" + this.E2; this.E3_Num.text = "X" + this.E3; 
        }
        /**购买敌机  CD条 */
        public Enemy1_money() {
            var x = this.Enemy1.x + this.Enemy1.width / 2;
            var y = this.Enemy1.y + this.Enemy1.height / 2;
            if (this.E1cd == null) {
                this.E1cd = new CdCircle.Circle();
            }
            this.E1Bool = this.E1cd.inCdTime;
            if (GameUtil.PlayerMessage.instance.money >= GameUtil.PlayerMessage.instance.planeConfig[1].price && GameUtil.PlayerMessage.instance.limitToBuyEnemy > 0 && !this.E1Bool) {
                this.E1cd.init(this, x, y, GameUtil.PlayerMessage.instance.planeConfig[1].cd);
                GameUtil.PlayerMessage.instance.money -= GameUtil.PlayerMessage.instance.planeConfig[1].price;
                GameUtil.PlayerMessage.instance.sendEnemy.push(EnemyType["敌机1_png"]);
                this.E1 += 1;
                this.SubtitleJumped.SubtitleJumped(GameUtil.PlayerMessage.instance.planeConfig[1].price, this.Enemy1);
                this.addChild(this.SubtitleJumped);
                

            }
        }
        public Enemy2_money() {
            var x = this.Enemy2.x + this.Enemy2.width / 2;
            var y = this.Enemy2.y + this.Enemy2.height / 2;
            if (this.E2cd == null) {
                this.E2cd = new CdCircle.Circle();
            }
            this.E2Bool = this.E2cd.inCdTime;
            if (GameUtil.PlayerMessage.instance.money >= GameUtil.PlayerMessage.instance.planeConfig[2].price && GameUtil.PlayerMessage.instance.limitToBuyEnemy > 0 && !this.E2Bool) {
                this.E2cd.init(this, x, y, GameUtil.PlayerMessage.instance.planeConfig[2].cd);
                GameUtil.PlayerMessage.instance.money -= GameUtil.PlayerMessage.instance.planeConfig[2].price;
                GameUtil.PlayerMessage.instance.sendEnemy.push(EnemyType["敌机2_png"]);
                this.E2 += 1;
                this.SubtitleJumped.SubtitleJumped(GameUtil.PlayerMessage.instance.planeConfig[2].price, this.Enemy2);
                this.addChild(this.SubtitleJumped);
                

            }
        }
        public Enemy3_money() {
            var x = this.Enemy3.x + this.Enemy3.width / 2;
            var y = this.Enemy3.y + this.Enemy3.height / 2;
            if (this.E3cd == null) {
                this.E3cd = new CdCircle.Circle();
            }
            this.E3Bool = this.E3cd.inCdTime;
            if (GameUtil.PlayerMessage.instance.money >= GameUtil.PlayerMessage.instance.planeConfig[3].price && GameUtil.PlayerMessage.instance.limitToBuyEnemy > 0 && !this.E3Bool) {
                this.E3cd.init(this, x, y, GameUtil.PlayerMessage.instance.planeConfig[3].cd);
                GameUtil.PlayerMessage.instance.money -= GameUtil.PlayerMessage.instance.planeConfig[3].price;
                GameUtil.PlayerMessage.instance.sendEnemy.push(EnemyType["敌机3_png"]);
                this.E3 += 1;
                this.SubtitleJumped.SubtitleJumped(GameUtil.PlayerMessage.instance.planeConfig[3].price, this.Enemy3);
                this.addChild(this.SubtitleJumped);
                

            }
        }
        public Enemy4_money() {
            var x = this.Enemy4.x + this.Enemy4.width / 2;
            var y = this.Enemy4.y + this.Enemy4.height / 2;
            if (this.E4cd == null) {
                this.E4cd = new CdCircle.Circle();
            }
            // this.E4Bool = this.E4cd.inCdTime;
            if (GameUtil.PlayerMessage.instance.money >= GameUtil.PlayerMessage.instance.planeConfig[4].price && GameUtil.PlayerMessage.instance.limitToBuyEnemy > 0 /*&& !this.E4Bool*/) {
                this.E4cd.init(this, x, y, GameUtil.PlayerMessage.instance.planeConfig[4].cd);
                GameUtil.PlayerMessage.instance.money -= GameUtil.PlayerMessage.instance.planeConfig[4].price;
                GameUtil.PlayerMessage.instance.sendEnemy.push(EnemyType["E4_png"]);
                // this.E4 += 1
                this.SubtitleJumped.SubtitleJumped(GameUtil.PlayerMessage.instance.planeConfig[4].price, this.Enemy4);
                this.addChild(this.SubtitleJumped);
            }
        }
        public Enemy5_money() {
            if (GameUtil.PlayerMessage.instance.money >= 60 && GameUtil.PlayerMessage.instance.limitToBuyEnemy > 0) {
                GameUtil.PlayerMessage.instance.money -= 60;
                // this.E5 += 1;
               // GameUtil.PlayerMessage.instance.sendEnemy.push(EnemyType["E5_png"]);
                this.SubtitleJumped.SubtitleJumped(20, this.Enemy5);
                this.addChild(this.SubtitleJumped);
                GameUtil.PlayerMessage.instance.limitToBuyEnemy--;
            }
        }
        public Enemy6_money() {
            if (GameUtil.PlayerMessage.instance.money >= 60 && GameUtil.PlayerMessage.instance.limitToBuyEnemy > 0) {
                GameUtil.PlayerMessage.instance.money -= 60;
                //  this.E5 += 1;
                GameUtil.PlayerMessage.instance.sendEnemy.push(EnemyType["E6_png"]);
                this.SubtitleJumped.SubtitleJumped(20, this.Enemy6);
                this.addChild(this.SubtitleJumped);
                GameUtil.PlayerMessage.instance.limitToBuyEnemy--;
            }
        }
        public Enemy7_money() {
            if (GameUtil.PlayerMessage.instance.money >= 60 && GameUtil.PlayerMessage.instance.limitToBuyEnemy > 0) {
                GameUtil.PlayerMessage.instance.money -= 60;
                // this.E5 += 1;
                GameUtil.PlayerMessage.instance.sendEnemy.push(EnemyType["E7_png"]);
                this.SubtitleJumped.SubtitleJumped(20, this.Enemy7);
                this.addChild(this.SubtitleJumped);
                GameUtil.PlayerMessage.instance.limitToBuyEnemy--;
            }
        }
        public Enemy8_money() {
            if (GameUtil.PlayerMessage.instance.money >= 60 && GameUtil.PlayerMessage.instance.limitToBuyEnemy > 0) {
                GameUtil.PlayerMessage.instance.money -= 60;
                //this.E5 += 1;
                GameUtil.PlayerMessage.instance.sendEnemy.push(EnemyType["E8_png"]);
                this.SubtitleJumped.SubtitleJumped(20, this.Enemy8);
                this.addChild(this.SubtitleJumped);
                GameUtil.PlayerMessage.instance.limitToBuyEnemy--;
            }
        }
        public Enemy9_money() {
            if (GameUtil.PlayerMessage.instance.money >= 60 && GameUtil.PlayerMessage.instance.limitToBuyEnemy > 0) {
                GameUtil.PlayerMessage.instance.money -= 60;
                //this.E5 += 1;
                GameUtil.PlayerMessage.instance.sendEnemy.push(EnemyType["E9_png"]);
                this.SubtitleJumped.SubtitleJumped(20, this.Enemy9);
                this.addChild(this.SubtitleJumped);
                GameUtil.PlayerMessage.instance.limitToBuyEnemy--;
            }
        }

    }
}